package cn.bandeqing;

import com.mybatisflex.codegen.Generator;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.zaxxer.hikari.HikariDataSource;

public class App {

    public static void main(String[] args) {

        //配置数据源
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/bandeqing");
        dataSource.setUsername("root");
        dataSource.setPassword("zhy_black.");

        //创建配置内容，两种风格都可以。
        GlobalConfig globalConfig = createGlobalConfigUseStyle();
        //GlobalConfig globalConfig = createGlobalConfigUseStyle2();

        //通过 datasource 和 globalConfig 创建代码生成器
        Generator generator = new Generator(dataSource, globalConfig);

        //生成代码
        generator.generate();

    }

    public static GlobalConfig createGlobalConfigUseStyle() {

        String tableName = "unipush2";
        String prefix = "bdq_";

        //创建配置内容
        GlobalConfig globalConfig = new GlobalConfig();

        globalConfig.setSourceDir("template");

        //设置根包
        globalConfig.setBasePackage("cn.bandeqing.unipush2");
//        globalConfig.setBasePackage("cn.bandeqing.shortMessage" + tableName);

        //设置表前缀和只生成哪些表
        globalConfig.setTablePrefix(prefix);
        globalConfig.setGenerateTable(prefix + tableName);

        //设置生成 entity 并启用 Lombok
        globalConfig.setEntityGenerateEnable(true);
        globalConfig.setEntityWithLombok(true);
        globalConfig.setEntityInterfaces(new Class[]{});
//        globalConfig.setEntitySuperClass();
//        globalConfig.setEntitySuperClass();

        //设置生成 mapper
        globalConfig.setMapperGenerateEnable(true);

        globalConfig.setServiceGenerateEnable(true);
        globalConfig.setServiceClassPrefix("I");

        globalConfig.setServiceImplGenerateEnable(true);

        globalConfig.setControllerGenerateEnable(true);

        //可以单独配置某个列
//        ColumnConfig columnConfig = new ColumnConfig();
//        columnConfig.setColumnName("tenant_id");
//        columnConfig.setLarge(true);
//        columnConfig.setVersion(true);
//        globalConfig.setColumnConfig("tb_account", columnConfig);

        return globalConfig;
    }

}
